package com.java.test53;

import java.util.Scanner;

public class Gardener {
	// 行为
	// 创建水果数组
	private Fruit[] fruits;

	// 构造方法
	public Gardener() {
		super();
		// 初始化数组
		fruits = new Fruit[5];
	}

	/**
	 * 园丁获取水果的行为
	 */
	public void creat() {
		// 使用面向接口的编程，其返回值与原有不同
		Fruit fruit = null;
		for (int i = 0; i < fruits.length; i++) {
			Scanner sc = new Scanner(System.in);
			System.out.println("请输入水果名字：");
			String str = sc.next();

			if (str.equalsIgnoreCase("apple")) {
				fruits[i] = new Apple();
			} else if (str.equalsIgnoreCase("pear")) {
				fruits[i] = new Pear();
			} else {
				fruits[i] = new Orange();
			}
		}

	}

	/**
	 * 调用父类的行为
	 */
	public void showMes() {
		for (Fruit fruit : fruits) {
			fruit.showFruit();
		}
	}

}
